#!/usr/bin/python
# -*- coding: UTF8 -*-

from selenium.webdriver.firefox.webdriver import WebDriver
from selenium import webdriver
import time
import logs

class mailru:
	
	def addPost(self, proxy, account, post):
		try:


			if(proxy == True):

				PROXY_HOST = "127.0.0.1"
				PROXY_PORT = 8118

				fp = webdriver.FirefoxProfile()

				# Direct = 0, Manual = 1, PAC = 2, AUTODETECT = 4, SYSTEM = 5
				fp.set_preference("network.proxy.type", 1)

				fp.set_preference("network.proxy.http", PROXY_HOST)
				fp.set_preference("network.proxy.http_port", PROXY_PORT)
				fp.set_preference("network.proxy.ftp", PROXY_HOST)
				fp.set_preference("network.proxy.ftp_port", PROXY_PORT)
				fp.set_preference("network.proxy.ssl", PROXY_HOST)
				fp.set_preference("network.proxy.ssl_port", PROXY_PORT)

				fp.set_preference("network.proxy.no_proxies_on", "") # set this value as desired

				#driver = webdriver.Firefox(firefox_profile=fp)



				driver = webdriver.Firefox(firefox_profile=fp) # Get local session of firefox
			else:
				driver = webdriver.Firefox()

			wd = driver
			wd.implicitly_wait(30)
			wd.get("http://e.mail.ru/cgi-bin/login")
			wd.find_element_by_id("login").send_keys(account[0])
			wd.find_element_by_id("password").send_keys(account[1])
			wd.find_element_by_xpath("//table[@class='login-form']/tbody/tr[3]/td[3]").click()
			wd.find_element_by_id("EnterBtn").click()
			time.sleep(5)
			wd.get("http://blogs.mail.ru/mail/"+account[0])
			wd.find_element_by_id("micropost_textarea").click()
			time.sleep(3)
			wd.find_element_by_id("micropost_textarea").send_keys(post)
			time.sleep(1)
			wd.find_element_by_id("micropost_add").click()
			time.sleep(7)
			
			wd.close()

			return True
		except :
			wd.close()
			
			return False

		
	
